home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / ab20 / ab20_archive / text / cmanual.lzh / ACM2.lzh / Requesters / Example5.c < prev    next >
C/C++ Source or Header  |  1990-01-30  |  14KB  |  356 lines

  1. /* Example5                                                             */
  2. /* This program will open a normal window which is connected to the     */
  3. /* Workbench Screen. The window will use all System Gadgets, and will   */
  4. /* close first when the user has selected the System gadget Close       */
  5. /* window. Whenever the user double-clicks on the right mouse button,   */
  6. /* a Double-menue requester is activated. This example also shows how   */
  7. /* to use the IDCMP flags REQSET and REQCLEAR.                          */
  8.  
  9.  
  10.  
  11. #include <intuition/intuition.h>
  12.  
  13.  
  14.  
  15. struct IntuitionBase *IntuitionBase;
  16.  
  17.  
  18.  
  19. /***************/
  20. /* THE GADGET: */
  21. /***************/
  22.  
  23. /* The coordinates for the box: */
  24. SHORT gadget_border_points[]=
  25. {
  26.    0,  0, /* Start at position (0,0) */
  27.   70,  0, /* Draw a line to the right to position (70,0) */
  28.   70, 10, /* Draw a line down to position (70,10) */
  29.    0, 10, /* Draw a line to the right to position (0,10) */
  30.    0,  0  /* Finish of by drawing a line up to position (0,0) */ 
  31. };
  32.  
  33. /* The Border structure: */
  34. struct Border gadget_border=
  35. {
  36.   0, 0,        /* LeftEdge, TopEdge. */
  37.   1,           /* FrontPen, colour register 1. */
  38.   0,           /* BackPen, for the moment unused. */
  39.   JAM1,        /* DrawMode, draw the lines with colour 1. */
  40.   5,           /* Count, 5 pair of coordinates in the array. */
  41.   gadget_border_points, /* XY, pointer to the array with the coord. */
  42.   NULL,        /* NextBorder, no other Border structures are connected. */
  43. };
  44.  
  45. /* The IntuiText structure: */
  46. struct IntuiText gadget_text=
  47. {
  48.   1,         /* FrontPen, colour register 1. */
  49.   0,         /* BackPen, colour register 0. */
  50.   JAM1,      /* DrawMode, draw the characters with colour 1, do not */
  51.              /* change the background. */ 
  52.   4, 2,      /* LeftEdge, TopEdge. */
  53.   NULL,      /* ITextFont, use default font. */
  54.   "PRESS ME",/* IText, the text that will be printed. */
  55.   NULL,      /* NextText, no other IntuiText structures are connected. */
  56. };
  57.  
  58. struct Gadget requester_gadget=
  59. {
  60.   NULL,          /* NextGadget, no more gadgets in the list. */
  61.   40,            /* LeftEdge, 40 pixels out. */
  62.   20,            /* TopEdge, 20 lines down. */
  63.   71,            /* Width, 71 pixels wide. */
  64.   11,            /* Height, 11 pixels lines heigh. */
  65.   GADGHCOMP,     /* Flags, when this gadget is highlighted, the gadget */
  66.                  /* will be rendered in the complement colours. */
  67.                  /* (Colour 0 (00) will be changed to colour 3 (11) */
  68.                  /* (Colour 1 (01)           - " -           2 (10) */
  69.                  /* (Colour 2 (10)           - " -           1 (01) */
  70.                  /* (Colour 3 (11)           - " -           0 (00) */  
  71.   GADGIMMEDIATE| /* Activation, our program will recieve a message when */
  72.   RELVERIFY|     /* the user has selected this gadget, and when the user */
  73.                  /* has released it. */
  74.   ENDGADGET,     /* When the user has selected this gadget, the */
  75.                  /* requester is satisfied, and is deactivated. */
  76.                  /* IMPORTANT! At least one gadget per requester */
  77.                  /* must have the flag ENDGADGET set. If not, the */
  78.                  /* requester would never be deactivated! */
  79.  
  80.   BOOLGADGET|    /* GadgetType, a Boolean gadget which is connected to */
  81.   REQGADGET,     /* a requester. IMPORTANT! Every gadget which is */
  82.                  /* connectd to a requester must have the REQGADGET flsg */
  83.                  /* set in the GadgetType field. */
  84.   (APTR) &gadget_border, /* GadgetRender, a pointer to our Border struc. */
  85.   NULL,          /* SelectRender, NULL since we do not supply the gadget */
  86.                  /* with an alternative image. (We complement the */
  87.                  /* colours instead) */
  88.   &gadget_text,  /* GadgetText, a pointer to our IntuiText structure. */
  89.                  /* (See chapter 3 GRAPHICS for more information) */
  90.   NULL,          /* MutualExclude, no mutual exclude. */
  91.   NULL,          /* SpecialInfo, NULL since this is a Boolean gadget. */
  92.                  /* (It is not a Proportional/String or Integer gdget) */
  93.   0,             /* GadgetID, no id. */
  94.   NULL           /* UserData, no user data connected to the gadget. */
  95. };
  96.  
  97. /***********************************************************************/
  98. /* Important notice:                                                   */
  99. /* Remember that every gadget which is connected to a requester must   */
  100. /* have the flag REQGADGET set in the GadgetType field. Remember also  */
  101. /* that at least one gadget per requester must have the ENDGADGET flag */
  102. /* set in the Activation field.                                        */
  103. /***********************************************************************/
  104.  
  105.  
  106.  
  107. /************************************/
  108. /* THE BORDER AROUND THE REQUESTER: */
  109. /************************************/
  110.  
  111. /* The coordinates for the box around the requester: */
  112. SHORT requester_border_points[]=
  113. {
  114.     0,  0, /* Start at position (0,0) */
  115.   319,  0, /* Draw a line to the right to position (319,0) */
  116.   319, 99, /* Draw a line down to position (319,99) */
  117.     0, 99, /* Draw a line to the right to position (319,99) */
  118.     0,  0  /* Finish of by drawing a line up to position (0,0) */ 
  119. };
  120.  
  121. /* The Border structure for the requester: */
  122. struct Border requester_border=
  123. {
  124.   0, 0,        /* LeftEdge, TopEdge. */
  125.   1,           /* FrontPen, colour register 1. */
  126.   0,           /* BackPen, for the moment unused. */
  127.   JAM1,        /* DrawMode, draw the lines with colour 1. */
  128.   5,           /* Count, 5 pair of coordinates in the array. */
  129.   requester_border_points, /* XY, pointer to the array with the coord. */
  130.   NULL,        /* NextBorder, no other Border structures are connected. */
  131. };
  132.  
  133.  
  134.  
  135. /**********************************/
  136. /* THE TEXT INSIDE THE REQUESTER: */
  137. /**********************************/
  138.  
  139. /* The IntuiText structure used to print some text inside the requester: */
  140. struct IntuiText requester_text=
  141. {
  142.   1,         /* FrontPen, colour register 1. */
  143.   0,         /* BackPen, unused since JAM1. */
  144.   JAM1,      /* DrawMode, draw the characters with colour 1, do not */
  145.              /* change the background. */ 
  146.   4, 2,      /* LeftEdge, TopEdge. */
  147.   NULL,      /* ITextFont, use default font. */
  148.   "This is the requester!", /* IText, the text that will be printed. */
  149.   NULL,      /* NextText, no other IntuiText structures are connected. */
  150. };
  151.  
  152.  
  153.  
  154. /* Note:                                                                */
  155. /* This is the structure for the Double-menu requester, but as you have */
  156. /* maybe noticed, it is exactly the same as a normal requester struc.   */
  157. /* The diffrence is that we call the function SetDMRequest() instead    */
  158. /* of calling the function Request().                                   */
  159.  
  160. struct Requester my_requester=
  161. {
  162.   NULL,              /* OlderRequester, used by Intuition. */
  163.   40, 20,            /* LeftEdge, TopEdge, 40 pixels out, 20 lines down. */
  164.   320, 100,          /* Width, Height, 320 pixels wide, 100 lines high. */
  165.   0, 0,              /* RelLeft, RelTop, Since POINTREL flag is not set, */
  166.                      /* Intuition ignores these values. */
  167.   &requester_gadget, /* ReqGadget, pointer to the first gadget. */
  168.   &requester_border, /* ReqBorder, pointer to a Border structure. */
  169.   &requester_text,   /* ReqText, pointer to a IntuiText structure. */
  170.   NULL,              /* Flags, no flags set. */
  171.   3,                 /* BackFill, draw everything on an orange backgr. */
  172.   NULL,              /* ReqLayer, used by Intuition. Set to NULL. */
  173.   NULL,              /* ReqPad1, used by Intuition. Set to NULL. */
  174.   NULL,              /* ImageBMap, no predrawn Bitmap. Set to NULL. */
  175.                      /*            (The PREDRAWN flag was not set) */
  176.   NULL,              /* RWindow, used by Intuition. Set to NULL. */
  177.   NULL               /* ReqPad2, used by Intuition. Set to NULL. */
  178. };
  179.  
  180.  
  181.  
  182. /* Declare a pointer to a Window structure: */ 
  183. struct Window *my_window;
  184.  
  185. /* Declare and initialize your NewWindow structure: */
  186. struct NewWindow my_new_window=
  187. {
  188.   0,             /* LeftEdge    x position of the window. */
  189.   0,             /* TopEdge     y positio of the window. */
  190.   640,           /* Width       640 pixels wide. */
  191.   200,           /* Height      200 lines high. */
  192.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  193.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  194.   CLOSEWINDOW|   /* IDCMPFlags  The window will give us a message if the */
  195.                  /*             user has selected the Close window gad, */
  196.   GADGETDOWN|    /*             or a gadget has been pressed on, or */
  197.   GADGETUP|      /*             a gadge has been released. */
  198.   REQSET|        /*             We will also recieve a message when the */
  199.   REQCLEAR,      /*             user has activated and deactivated a req. */
  200.   SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  201.   WINDOWCLOSE|   /*             Close Gadget. */
  202.   WINDOWDRAG|    /*             Drag gadget. */
  203.   WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  204.   WINDOWSIZING|  /*             Sizing Gadget. */
  205.   ACTIVATE,      /*             The window should be Active when opened. */
  206.   NULL,          /* FirstGadget No gadget connected to this window. */
  207.   NULL,          /* CheckMark   Use Intuition's default CheckMark. */
  208.   "The Fantastic Window!",      /* Title       Title of the window. */
  209.   NULL,          /* Screen      Connected to the Workbench Screen. */
  210.   NULL,          /* BitMap      No Custom BitMap. */
  211.   140,           /* MinWidth    We will not allow the window to become */
  212.   50,            /* MinHeight   smaller than 140 x 50, and not bigger */
  213.   300,           /* MaxWidth    than 300 x 200. */
  214.   200,           /* MaxHeight */
  215.   WBENCHSCREEN   /* Type        Connected to the Workbench Screen. */
  216. };
  217.  
  218. /* Note:                                                         */
  219. /* Since we want to know when the user selects and deselects the */
  220. /* DMRequester, we set the IDCMP flags REQSET and REQCLEAR.      */
  221.  
  222.  
  223.  
  224. main()
  225. {
  226.   /* Boolean variable used for the while loop: */
  227.   BOOL close_me;
  228.  
  229.   /* Declare a variable in which we will store the IDCMP flag: */
  230.   ULONG class;
  231.   
  232.   /* Declare a pointer to an IntuiMessage structure: */
  233.   struct IntuiMessage *my_message;
  234.  
  235.   /* We use this variable to check if Intuition could enable the user */
  236.   /* to bring up the requester whenever he/she wants: */
  237.   BOOL result;
  238.  
  239.  
  240.  
  241.   /* Before we can use Intuition we need to open the Intuition Library: */
  242.   IntuitionBase = (struct IntuitionBase *)
  243.     OpenLibrary( "intuition.library", 0 );
  244.   
  245.   if( IntuitionBase == NULL )
  246.     exit(); /* Could NOT open the Intuition Library! */
  247.  
  248.  
  249.  
  250.   /* We will now try to open the window: */
  251.   my_window = (struct Window *) OpenWindow( &my_new_window );
  252.   
  253.   /* Have we opened the window succesfully? */
  254.   if(my_window == NULL)
  255.   {
  256.     /* Could NOT open the Window! */
  257.     
  258.     /* Close the Intuition Library since we have opened it: */
  259.     CloseLibrary( IntuitionBase );
  260.  
  261.     exit();  
  262.   }
  263.  
  264.  
  265.  
  266.   /* We have opened the window, and everything seems to be OK. */
  267.  
  268.  
  269.  
  270.   /* We will now try to set the Double-menu requester: */
  271.   result=SetDMRequest( my_window, &my_requester );
  272.  
  273.   if( !result )  /* !result is the same thing as result==FALSE */
  274.   {
  275.     /* Intuition could not set the Double-menu requester! */
  276.   
  277.     printf("Could not set the Double-menu requester!\n");
  278.   }
  279.   else
  280.   {
  281.     /* OK */
  282.     printf("Try to double-click on the right mouse button!\n\n");
  283.   }
  284.  
  285.  
  286.   close_me = FALSE;
  287.  
  288.   /* Stay in the while loop until the user has selected the Close window */
  289.   /* gadget: */
  290.   while( !close_me )
  291.   {
  292.     /* Wait until we have recieved a message: */
  293.     Wait( 1 << my_window->UserPort->mp_SigBit );
  294.  
  295.     /* As long as we collect messages sucessfully: */
  296.     while(my_message=(struct IntuiMessage *) GetMsg(my_window->UserPort))
  297.     {
  298.       /* After we have collected the message we can read it, and save any */
  299.       /* important values which we maybe want to check later: */
  300.       class = my_message->Class;
  301.  
  302.       /* After we have read it we reply as fast as possible: */
  303.       /* REMEMBER! Do never try to read a message after you have replied! */
  304.       /* Some other process has maybe changed it. */
  305.       ReplyMsg( my_message );
  306.  
  307.       /* Check which IDCMP flag was sent: */
  308.       switch( class )
  309.       {
  310.         case CLOSEWINDOW:  /* The user selected the Close window gadget! */
  311.                close_me=TRUE;
  312.                break;
  313.              
  314.         case GADGETDOWN:   /* The user has pressed on a gadget. */
  315.                /* Since there exist only one "nomal" gadget, we do not */
  316.                /* need to check which gadget was selected. */
  317.                
  318.                printf("Gadget down\n");
  319.                break;
  320.              
  321.         case GADGETUP:     /* The user has released a gadget. */
  322.                /* Since there exist only one "nomal" gadget, we do not */
  323.                /* need to check which gadget was released. */
  324.                
  325.                /* Once we recieve this message, the requester will be */
  326.                /* satisfied, and therefore deactivated. We will */
  327.                /* therefore also recieve a REQCLEAR message. */
  328.                
  329.                printf("Gadget up\n");
  330.                break;
  331.                
  332.         case REQSET:       /* Requester activated. */
  333.                printf("Requester activated!\n");
  334.                printf("You can not close the window now.\n");
  335.                break;
  336.                
  337.         case REQCLEAR:     /* Requester deactivated. */
  338.                printf("Requester deactivated!\n");
  339.                printf("You can close the window now.\n\n");
  340.                break;
  341.       }
  342.     }
  343.   }
  344.  
  345.  
  346.  
  347.   /* We should always close the windows we have opened before we leave: */
  348.   CloseWindow( my_window );
  349.  
  350.  
  351.  
  352.   /* Close the Intuition Library since we have opened it: */
  353.   CloseLibrary( IntuitionBase );
  354.   
  355.   /* THE END */
  356. }